package com.huarui.employee.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.model.ListModel;
import org.ewaf.framework.service.BaseService;

import com.huarui.dictionary.DictionaryEnum;
import com.huarui.dictionary.service.DictionaryReadOnlyService;
import com.huarui.employee.dao.IHireHistoryDao;
import com.huarui.employee.model.HireHistory;

public class HireHistoryService extends BaseService {

	private DictionaryReadOnlyService dictionaryReadOnlyService;

	public void setDictionaryReadOnlyService(
			DictionaryReadOnlyService dictionaryReadOnlyService) {

		this.dictionaryReadOnlyService = dictionaryReadOnlyService;
	}

	private IHireHistoryDao getDao() {
		return (IHireHistoryDao) dao;
	}

	public HireHistory getHireHistoryByGmt(Integer userId, Date gmtCreate) {

		return getDao().getHireHistoryByGmt(userId, gmtCreate);
	}

	public List<HireHistory> getByCompanyId(Integer companyId) {

		return getDao().getByCompanyId(companyId);
	}

	@SuppressWarnings("unchecked")
	public ListModel<HireHistory> getByUserId(Integer userId, ListModel lm) {

		lm.setTotal(this.getDao().countByConditions(userId));
		Map map = new HashMap<String, String>();
		map.put("userId", userId);
		map.put("orderBy", lm.getOrderBy());
		map.put("start", lm.getStart());
		map.put("pageSize", lm.getPageSize());
		map.put("desc", lm.isDesc());

		List<HireHistory> hireHistoryList = getDao().getByUserId(map);

		for (HireHistory hireHistory : hireHistoryList) {

			String typeName = dictionaryReadOnlyService.getDictionaryValue(
					DictionaryEnum.GROUP_HIREHISTORY_TYPE, hireHistory
							.getType());

			hireHistory.setTypeName(typeName);

		}
		lm.setResult(hireHistoryList);

		return lm;

	}
}
